package com.team233.zuccecho.controller;

import com.team233.zuccecho.dto.ClazzDto;
import com.team233.zuccecho.dto.CourseDto;
import com.team233.zuccecho.result.ExceptionMsg;
import com.team233.zuccecho.result.ResponseData;
import com.team233.zuccecho.service.inter.CourseInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 课程管理
 */
@RestController
@RequestMapping("v1")
public class CourseController {
    @Autowired
    private CourseInterface courseInterface;

    //创建Course(可以包含具体的clazz列表)
    @PostMapping("course/add")
    public ResponseData AddCourse(@RequestBody CourseDto courseDto){
        long id=courseInterface.addCourse(courseDto);
        return new ResponseData(ExceptionMsg.SUCCESS,id);
    }

    //注销Course
    @PostMapping("course/delete")
    public ResponseData DeleteCourse(@RequestBody Map<String,List<CourseDto>> body){
        courseInterface.deleteCourse(body.get("courses"));
        return new ResponseData(ExceptionMsg.SUCCESS,"注销Course成功");
    }

    //创建clazz
    @PostMapping("clazz/create")
    public ResponseData CreateClazz(@RequestBody Map<String,List<ClazzDto>> body){
        courseInterface.addClazz(body.get("clazzes"));
        return new ResponseData(ExceptionMsg.SUCCESS,"创建成功");
    }

    //关闭课程
    @PostMapping("clazz/delete")
    public ResponseData DeleteClazz(@RequestBody Map<String,List<ClazzDto>> body){
        courseInterface.deleteClazz(body.get("clazzes"));
        return new ResponseData(ExceptionMsg.SUCCESS,"删除成功");
    }

    //为clazz分配老师
    @PostMapping("clazz/addTeacher")
    public ResponseData ClazzByTea(@RequestBody Map<String,List<ClazzDto>> body){
        courseInterface.AddTea(body.get("clazzes"));
        return new ResponseData(ExceptionMsg.SUCCESS,"添加教师成功");
    }

    //为clazz分配学生
    @PostMapping("clazz/addStudent")
    public ResponseData ClazzByStuList(@RequestBody Map<String,List<ClazzDto>> body){
        courseInterface.AddStu(body.get("clazzes"));
        return new ResponseData(ExceptionMsg.SUCCESS,"添加学生成功");
    }

    //移除clazz中的学生
    @PostMapping("clazz/deleteStudent")
    public ResponseData ClazzDeleteStu(@RequestBody Map<String,List<ClazzDto>> body){
        courseInterface.RemoveStu(body.get("clazzes"));
        return new ResponseData(ExceptionMsg.SUCCESS,"移除学生成功");
    }
}
